package com.zfcoding.redis.controller;


import com.zfcoding.redis.entity.User;
import com.zfcoding.redis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

@RestController
@RequestMapping("/users")
public class UserController {

    @GetMapping
    public User getUser(@RequestParam("id") Integer id) throws Exception{

        try{
            return userService.getUser(id);
        }
        catch(Exception ex){
            return new User(0L,ex.getMessage(),0,null);
        }
    }

    @Autowired
    private UserService userService;


    @PostMapping()
    public Boolean postUser(User user){
        return this.userService.saveUser(user);
    }

}
